﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model.Common;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.DAO;
using System.Data;

/// <summary>
/// Summary description for CityController
/// </summary>
/// 
namespace br.com.SistemaChamados.Controller
{

    public class CityController
    {
        public EnumGenericState updateCity(City city)
        {
            EnumGenericState resultState = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                CityDAO cityDAO = new CityDAO();
                resultState = cityDAO.updateCity(city);
            }
            catch (Exception ex)
            {
                resultState = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return resultState;
        }

        public List<City> listCity()
        {
            List<City> listCity = null;
            CityDAO cityDAO = null;
            try
            {
                cityDAO = new CityDAO();
                listCity = cityDAO.listCity();
                if (listCity != null)
                {
                    return listCity;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
                throw;
            }
        }

        public List<City> listCityByState(State state)
        {
            List<City> listCity = null;
            CityDAO cityDAO = null;
            try
            {
                cityDAO = new CityDAO();
                listCity = cityDAO.listCityByState(state);
                if (listCity != null)
                {
                    return listCity;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
                throw;
            }
        }

        public City SelectCity(City city)
        {
            City newCity = null;
            CityDAO cityDAO = null;
            try
            {
                cityDAO = new CityDAO();
                newCity = cityDAO.SelectCity(city);
                if (newCity != null)
                {
                    return newCity;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
                throw;
            }
        }
       
        public EnumGenericState deleteCity(City city)
        {
            EnumGenericState resultState = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                CityDAO cityDAO = new CityDAO();
                resultState = cityDAO.deleteCity(city);
            }
            catch (Exception ex)
            {
                resultState = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return resultState;
        }

        public EnumGenericState addCity(City city)
        {
            EnumGenericState resultState = EnumGenericState.GENERIC_STATE_UNKNOW;         
            try
            {
                CityDAO cityDAO = new CityDAO();
                resultState = cityDAO.addCity(city);
            }
            catch (Exception ex)
            {
                resultState = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return resultState;
        }
        public CityController()
        {

        }
    }
}